/*
 *  This file is part of ZiggyStardust.
 *
 *  ZiggyStardust is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  ZiggyStardust is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.wisc.csvParser.plugins;

/**
 *
 * @author  lawinslow
 */
public class JPanelDT extends javax.swing.JPanel {
    
    private DataRepositoryDT repo;
    
    /** Creates new form JPanelDT
     * @param dt Underlying data repository class.
     */
    public JPanelDT(DataRepositoryDT dt) {
        initComponents();
        repo = dt;
        
        repo.addListener(new DataRepositoryDT.DTListener(){
            @Override
            public void eventRaised(DataRepositoryDT.events e){
                someEventRaised(e);
            }
        });
        
    }
    
    
    public void someEventRaised(DataRepositoryDT.events e){
        if(e == DataRepositoryDT.events.reconfigured){
            dtHost.setText(repo.getDtHost());
        }else if(e == DataRepositoryDT.events.started ||
                e == DataRepositoryDT.events.stopped){
            startedCB.setSelected(repo.isStarted());
            saveButton.setEnabled(!repo.isStarted());
        }else if(e == DataRepositoryDT.events.valueBuffered ||
                e == DataRepositoryDT.events.valueDeBuffered){
            valuesCachedLabel.setText("Values Cached: " 
                    +Integer.toString(repo.getValsBuffered()));
        }else if(e == DataRepositoryDT.events.valuePassed){
            valuesPassedLabel.setText("Values Passed: "
                    +Long.toString(repo.getValsPassed()));
        }
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dtHost = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        startedCB = new javax.swing.JCheckBox();
        valuesPassedLabel = new javax.swing.JLabel();
        valuesCachedLabel = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();

        jLabel1.setText("DT Host:");

        startedCB.setText("Started");
        startedCB.setEnabled(false);

        valuesPassedLabel.setText("Values Passed: 0");

        valuesCachedLabel.setText("Values Cached: 0");

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(valuesCachedLabel)
                    .addComponent(valuesPassedLabel)
                    .addComponent(saveButton)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dtHost, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
                .addComponent(startedCB)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(dtHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(startedCB, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(valuesPassedLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(valuesCachedLabel)
                .addContainerGap(195, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        repo.setDtHost(dtHost.getText());
}//GEN-LAST:event_saveButtonActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField dtHost;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton saveButton;
    private javax.swing.JCheckBox startedCB;
    private javax.swing.JLabel valuesCachedLabel;
    private javax.swing.JLabel valuesPassedLabel;
    // End of variables declaration//GEN-END:variables
    
}
